package com.yida.wy.vote.outside.controller;

import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.wy.vote.outside.domain.dto.WyVoteResultDetailItemDTO;
import com.yida.wy.vote.outside.domain.dto.WyVoteResultDetailOptionCountDTO;
import com.yida.wy.vote.outside.domain.request.WyVoteResultDetailQueryRequest;
import com.yida.wy.vote.outside.domain.dto.WyEVoteResultDetailListDTO;
import com.yida.wy.vote.outside.domain.dto.WyGVoteResultDetailListDTO;
import com.yida.wy.vote.outside.service.IWyVoteResultDetailService;
import com.yida.wy.vote.outside.service.IWyVoteStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lqq
 * @date 2023-03-14
 */
@Api(tags = "投票结果详情")
@RestController
@RequestMapping("/detail")
public class WyVoteResultDetailController extends BaseController {

	@Resource
	private IWyVoteResultDetailService voteResultDetailService;

	@Resource
	private IWyVoteStatisticsService voteStatisticsService;

	@ApiOperation(value = "查询电子投票记录", response = WyEVoteResultDetailListDTO.class)
	@RequiresPermissions("gwj:vote:outside:e:project:statistics")
	@GetMapping("/e/list")
	public TableDataInfo list(@Validated WyVoteResultDetailQueryRequest request) {
		startPage();
		List<WyEVoteResultDetailListDTO> list = voteResultDetailService.selectEVoteResultDetailDTOList(request);
		return getDataTable(list);
	}

	@ApiOperation(value = "查询公维金投票记录", response = WyGVoteResultDetailListDTO.class)
	@RequiresPermissions("gwj:vote:outside:g:project:statistics")
	@GetMapping("/g/list")
	public TableDataInfo gList(@Validated WyVoteResultDetailQueryRequest request) {
		startPage();
		List<WyGVoteResultDetailListDTO> list = voteResultDetailService.selectGVoteResultDetailDTOList(request);
		return getDataTable(list);
	}

//	@ApiOperation("导出投票记录")
//	@RequiresPermissions("gwj:vote:outside:detail:export")
//	@Log(title = "公维金外网投票-导出投票记录", businessType = BusinessType.EXPORT, systemName = "vote")
//	@PostMapping("/export/{voteId}")
//	public void export(HttpServletResponse response, @PathVariable Long voteId) {
//		List<GwjEVoteResultDetailListDTO> list = voteResultDetailService.selectEVoteResultDetailDTOList(new GwjVoteResultDetailQueryRequest() {{
//			setVoteId(voteId);
//		}});
//		ExcelUtil<GwjVoteResultDetailExcelVO> util = new ExcelUtil<GwjVoteResultDetailExcelVO>(GwjVoteResultDetailExcelVO.class);
//		util.exportExcel(response, BeanUtil.copyToList(list, GwjVoteResultDetailExcelVO.class), "投票结果详情数据");
//	}

	@ApiOperation(value = "查询电子票数票数详细", response = WyVoteResultDetailItemDTO.class)
	@RequiresPermissions("gwj:vote:outside:e:project:statistics")
	@GetMapping("/e/count/{voteId}")
	public AjaxResult eDetailCount(@PathVariable Long voteId) {
		return AjaxResult.success(voteStatisticsService.voteResultDetailStatistics(voteId));
	}

	@ApiOperation(value = "查询公维金投票票数详细", response = WyVoteResultDetailOptionCountDTO.class)
	@RequiresPermissions("gwj:vote:outside:g:project:statistics")
	@GetMapping("/g/count/{voteId}")
	public AjaxResult gDetailCount(@PathVariable Long voteId) {
		return AjaxResult.success(voteStatisticsService.voteResultDetailStatistics(voteId));
	}
}
